
import delimited "final dataset.csv", clear 

*coding up the treatment conditions
gen female_control=1 if q20_1~=.
gen female_democrat=1 if q151_1~=.
gen female_liberal=1 if q185_1~=.
gen female_sanders=1 if q191_1~=.
gen female_republican=1 if q161_1~=.
gen female_conservative=1 if q204_1~=.
gen female_trump=1 if q210_1~=.

gen male_control=1 if q38_1~=.
gen male_democrat=1 if q253_1~=.
gen male_liberal=1 if q265_1~=.
gen male_sanders=1 if q277_1~=.
gen male_republican=1 if q173_1~=.
gen male_conservative=1 if q237_1~=.
gen male_trump=1 if q243_1~=.

gen control=1 if female_control==1 | male_control==1
gen democrat=1 if female_democrat==1 | male_democrat==1
gen liberal=1 if female_liberal==1 | male_liberal==1
gen sanders=1 if female_sanders==1 | male_sanders==1
gen republican=1 if female_republican==1 | male_republican==1
gen conservative=1 if female_conservative==1 | male_conservative==1
gen trump=1 if female_trump==1 | male_trump==1

gen none=1 if control==. &  democrat==. &  liberal==. &  sanders==. &  republican==. &  conservative==. &  trump==. 

foreach var in control democrat liberal sanders republican conservative trump {
replace `var'=0 if `var'==. & none~=1
}

drop if none==1

*coding up the dependent variables

gen attractiveness_score=q20_1
replace attractiveness_score=q151_1 if attractiveness_score==.
replace attractiveness_score=q185_1 if attractiveness_score==.
replace attractiveness_score=q191_1 if attractiveness_score==.
replace attractiveness_score=q161_1 if attractiveness_score==.
replace attractiveness_score=q204_1 if attractiveness_score==.
replace attractiveness_score=q210_1 if attractiveness_score==.
replace attractiveness_score=q38_1 if attractiveness_score==.
replace attractiveness_score=q253_1 if attractiveness_score==.
replace attractiveness_score=q265_1 if attractiveness_score==.
replace attractiveness_score=q277_1 if attractiveness_score==.
replace attractiveness_score=q173_1 if attractiveness_score==.
replace attractiveness_score=q237_1 if attractiveness_score==.
replace attractiveness_score=q243_1 if attractiveness_score==.

egen attractiveness_score_std=std(attractiveness_score), mean(0) std(1)

regress attractiveness_score_std democrat liberal sanders republican conservative trump

gen same_candidate=1 if q159=="Bernie Sanders" & sanders==1
replace same_candidate=1 if q159=="Donald Trump" & trump==1
replace same_candidate=0 if same_candidate==.

gen same_party=1 if q13=="Democrat" & democrat==1
replace same_party=1 if q13=="Republican" & republican==1
replace same_party=0 if same_party==. & q13~="Independent"

gen same_ideology=1 if (q12=="Liberal" | q12=="Very liberal") & liberal==1
replace same_ideology=1 if (q12=="Conservative" | q12=="Very conservative") & conservative==1
replace same_ideology=0 if same_ideology==. & q12~="Moderate"

gen message=6 if q21=="Definitely"
replace message=5 if q21=="Very probably"
replace message=4 if q21=="Probably"
replace message=3 if q21=="Possibly"
replace message=2 if q21=="Probably not"
replace message=1 if q21=="Definitely not"

foreach var in q152 q186 q192 q162 q205 q211 q39 q254 q266 q278 q174 q238 q244  {
replace message=6 if `var'=="Definitely"
replace message=5 if `var'=="Very probably"
replace message=4 if `var'=="Probably"
replace message=3 if `var'=="Possibly"
replace message=2 if `var'=="Probably not"
replace message=1 if `var'=="Definitely not"
}
egen message_std=std(message), mean(0) std(1)

gen go_on_a_date=6 if q22=="Definitely"
replace go_on_a_date=5 if q22=="Very probably"
replace go_on_a_date=4 if q22=="Probably"
replace go_on_a_date=3 if q22=="Possibly"
replace go_on_a_date=2 if q22=="Probably not"
replace go_on_a_date=1 if q22=="Definitely not"

foreach var in q153 q187 q193 q163 q206 q212 q40 q255 q267 q279 q175 q239 q245  {
replace go_on_a_date=6 if `var'=="Definitely"
replace go_on_a_date=5 if `var'=="Very probably"
replace go_on_a_date=4 if `var'=="Probably"
replace go_on_a_date=3 if `var'=="Possibly"
replace go_on_a_date=2 if `var'=="Probably not"
replace go_on_a_date=1 if `var'=="Definitely not"
}

egen go_on_a_date_std=std(go_on_a_date), mean(0) std(1)

gen relationship=6 if q23=="Definitely"
replace relationship=5 if q23=="Very probably"
replace relationship=4 if q23=="Probably"
replace relationship=3 if q23=="Possibly"
replace relationship=2 if q23=="Probably not"
replace relationship=1 if q23=="Definitely not"

foreach var in q154 q188 q194 q164 q207 q213 q41 q256 q268 q280 q176 q240 q246  {
replace relationship=6 if `var'=="Definitely"
replace relationship=5 if `var'=="Very probably"
replace relationship=4 if `var'=="Probably"
replace relationship=3 if `var'=="Possibly"
replace relationship=2 if `var'=="Probably not"
replace relationship=1 if `var'=="Definitely not"
}

egen relationship_std=std(relationship), mean(0) std(1)

gen setup=6 if q24=="Definitely"
replace setup=5 if q24=="Very probably"
replace setup=4 if q24=="Probably"
replace setup=3 if q24=="Possibly"
replace setup=2 if q24=="Probably not"
replace setup=1 if q24=="Definitely not"

foreach var in q155 q189 q195 q165 q208 q214 q42 q257 q269 q281 q177 q241 q247  {
replace setup=6 if `var'=="Definitely"
replace setup=5 if `var'=="Very probably"
replace setup=4 if `var'=="Probably"
replace setup=3 if `var'=="Possibly"
replace setup=2 if `var'=="Probably not"
replace setup=1 if `var'=="Definitely not"
}

egen setup_std=std(setup), mean(0) std(1)


*** Analysis

regress attractiveness_score_std same_party same_candidate same_ideology // for the meta-analysis in Figure 1
test same_party=same_candidate
test same_party=same_ideology
test same_candidate=same_ideology

foreach var in message_std go_on_a_date_std relationship_std setup_std {
	regress `var' same_party same_candidate same_ideology
	test same_party=same_candidate
	test same_party=same_ideology
	test same_candidate=same_ideology
}

gen age=2020-q2
regress attractiveness_score_std same_party same_candidate same_ideology if age>=18 & age<=35
test same_party=same_candidate
test same_party=same_ideology
test same_candidate=same_ideology

foreach var in message_std go_on_a_date_std relationship_std setup_std {
	regress `var' same_party same_candidate same_ideology if age>=18 & age<=35
	test same_party=same_candidate
	test same_party=same_ideology
	test same_candidate=same_ideology
}

*Factor Weighted Scale
factor attractiveness_score message go_on_a_date relationship
predict interact_scale

egen interact_scale_std=std(interact_scale), mean(0) std(1)

regress interact_scale_std same_party same_candidate same_ideology	
	


***********************************************************
*************************Balance Tests ********************
***********************************************************

*age (already coded)

*gender
gen male = .
replace male = 1 if q3 == "Male"
replace male = 0 if q3 == "Female"

*education
gen educ = .
replace educ = 1 if q4 == "Did not graduate from high school"
replace educ = 2 if q4 == "High school graduate"
replace educ = 3 if q4 == "Some college, but no degree (yet)"
replace educ = 4 if q4 == "2-year college degree"
replace educ = 5 if q4 == "4-year college degree"
replace educ = 6 if q4 == "Postgraduate degree (MA, MBA, MD, JD, PhD, etc.)"

*marriage status
replace q5=trim(q5)
gen married=1 if q5=="Married"
replace married=0 if q5~="Married" & q5~=""

*race
replace q14_1=trim(q14_1)
gen white = 1 if q14_1~=""
replace white = 0 if q14_1==""

*sexuality
gen straight = .
replace straight = 1 if q7 == "Heterosexual/straight"
replace straight = 0 if q7 != "Heterosexual/straight" & q7 !=""

*transgender
gen trans = .
replace trans = 1 if q8 == "Yes"
replace trans = 0 if q8 != "Yes" & q8 != "Prefer not to say"

*religiosity
gen religiosity = .
replace religiosity = 1 if q16 == "Not at all important"
replace religiosity = 2 if q16 == "Slightly important"
replace religiosity = 3 if q16 == "Moderately important"
replace religiosity = 4 if q16 == "Very important"
replace religiosity = 5 if q16 == "Extremely important"

*ideology
gen ideo5 = .
replace ideo5 = 1 if q12 == "Very conservative"
replace ideo5 = 2 if q12 == "Conservative"
replace ideo5 = 3 if q12 == "Moderate"
replace ideo5 = 4 if q12 == "Liberal"
replace ideo5 = 5 if q12 == "Very liberal"

*partyid
gen democrat_respondent=1 if q13=="Democrat"
replace democrat_respondent=0 if q13=="Independent" |  q13=="Republican"

*political interest
gen poli_interest = .
replace poli_interest = 1 if q9 == "Hardly at all"
replace poli_interest = 2 if q9 == "Only now and then"
replace poli_interest = 3 if q9 == "Some of the time"
replace poli_interest = 4 if q9 == "Most of the time"

*employment
replace q10=trim(q10)
gen employed=1 if q10=="Working full time now"
replace employed=0 if q10~="Working full time now" & q10~=""

*income
tab q132
gen income = .
replace income = 1 if q132 == "Less than $10,000"
replace income = 2 if q132 == "$10,000 - $19,999"
replace income = 3 if q132 == "$20,000 - $29,999"
replace income = 4 if q132 == "$30,000 - $39,999"
replace income = 5 if q132 == "$40,000 - $49,999"
replace income = 6 if q132 == "$50,000 - $59,999"
replace income = 7 if q132 == "$60,000 - $69,999"
replace income = 8 if q132 == "$70,000 - $79,999"
replace income = 9 if q132 == "$80,000 - $89,999"
replace income = 10 if q132 == "$90,000 - $99,999"
replace income = 11 if q132 == "$100,000 - $119,999"
replace income = 12 if q132 == "$120,000 - $149,999"
replace income = 13 if q132 == "$150,000 - $199,999"
replace income = 14 if q132 == "$200,000 - $249,999"
replace income = 15 if q132 == "$250,000 - $349,999"
replace income = 16 if q132 == "$350,000 - $499,999"
replace income = 17 if q132 == "$500,000 or more"


***********************************************************
*************************Balance Tests ********************
***********************************************************

sum age male educ white democrat_respondent ideo5 employed straight trans religiosity poli_interest income


egen age_std=std(age), mean(0) std(1)

regress age_std same_party
regsave same_party using "balance_experiment_5.dta", detail(all) addlabel(outcome, age, experiment, 5) replace 


foreach var in  male educ white democrat_respondent ideo5 employed straight trans religiosity poli_interest income {
egen `var'_std=std(`var'), mean(0) std(1)
regress `var'_std same_party
regsave same_party using "balance_experiment_5.dta", detail(all) addlabel(outcome, `var', experiment, 5) append 
}


foreach var in attractiveness_score message_std go_on_a_date_std relationship_std setup_std  ///
 age male educ white democrat_respondent ideo5 employed straight trans religiosity poli_interest income {
 
 gen `var'm=1 if `var'==.
 replace `var'm=0 if `var'~=.
 
 }
 
 foreach var in  attractiveness_score message_std go_on_a_date_std relationship_std setup_std  ///
 age male educ white democrat_respondent ideo5 employed straight trans religiosity poli_interest income {
tab `var'm
}

rename message  respond_message
rename go_on_a_date go_date
rename setup  set_up_friend

keep same_party age male educ white democrat_respondent ideo5 employed straight trans religiosity poli_interest income attractiveness_scorem message_stdm go_on_a_date_stdm relationship_stdm setup_stdm  agem malem educm whitem democrat_respondentm ideo5m employedm straightm transm religiositym poli_interestm incomem attractiveness_score respond_message go_date relationship  set_up_friend married

rename setup_stdm  set_up_friendm
rename message_stdm respond_messagem 
rename relationship_stdm relationshipm
rename go_on_a_date_stdm go_datem 

gen experiment=5
save "pared_balance_experiment_5.dta", replace

use "balance_experiment_5.dta", clear

gen t=coef/stderr

saveold "balance_experiment_5.dta", version(12) replace
		


